<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 构造函数
        function Pet(name, age) {
            this.name = name
            this.age = age;
        }

        // 添加名称方法
        Pet.prototype.getName = function() {
            return this.name;
        }

        // 添加年龄方法
        Pet.prototype.getAge = function() {
            return this.age;
        }
        
        // Dog继承Pet
        function Dog(name, age, color) {
            Pet.call(this, name, age);// 调用父类构造函数
            this.color = color;// 添加颜色属性
        }

        Dog.prototype =                       .create(Pet.prototype);// 继承父类原型
        Dog.prototype.constructor = Dog;// 修改构造函数指向

        // 返回颜色方法
        Dog.prototype.getColor = function() {
            return this.color;
        }
        
        var dog = new Dog('旺财', 3, '黄色');

        console.log('动物昵称' + dog.getName());
        console.log('动物年龄' + dog.getAge());
        console.log('动物颜色' + dog.getColor());
    </script>
</body>
</html>